﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.DAL;

namespace Ket_noi_toi_VPP_bang_mo_hinh_ba_lop
{
    public partial class FormNhanVien : Form
    {
        NhanVien NV = new NhanVien();
        public FormNhanVien()
        {
            InitializeComponent();
        }

        private void FormNhanVien_Load(object sender, EventArgs e)
        {
            dtgHienThi.DataSource = NV.SelectAll();
        }

        private void btReset_Click(object sender, EventArgs e)
        {
            this.tbMaNV.Clear();
            this.tbHoTen.Clear();
            this.tbNgaySinh.Clear();
            this.tbDT.Clear();
            this.tbDiaChi.Clear();
            this.tbGT.Clear();
            this.tbTenDN.Clear();
            this.tbPass.Clear();
            this.tbQuyenDN.Clear();
            this.tbMaNV.Focus();
        }

        private void btInsert_Click(object sender, EventArgs e)
        {
            NV.Insert(tbHoTen.Text, Convert.ToDateTime(tbNgaySinh.Text), tbDT.Text, tbDiaChi.Text, tbGT.Text, tbTenDN.Text, tbPass.Text,tbQuyenDN.Text);
            FormNhanVien_Load(sender,e);
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            NV.Delete(Convert.ToInt32(tbMaNV.Text));
            dtgHienThi.DataSource = NV.SelectAll();
        }

        private void btSelect_Click(object sender, EventArgs e)
        {
            dtgHienThi.DataSource = NV.SelectID(Convert.ToInt32(tbMaNV.Text));
        }

        private void btUpdate_Click(object sender, EventArgs e)
        {
            NV.Update(Convert.ToInt32(tbMaNV.Text), tbHoTen.Text, Convert.ToDateTime(tbNgaySinh.Text), tbDT.Text, tbDiaChi.Text, tbGT.Text, tbTenDN.Text, tbPass.Text,tbQuyenDN.Text);
            dtgHienThi.DataSource = NV.SelectAll();
            FormNhanVien_Load(sender,e);
        }

        private void btThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dtgHienThi_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            string ID;
            int dong;
            dong = e.RowIndex;
            ID = dtgHienThi.Rows[dong].Cells[2].Value.ToString();
            tbMaNV.Text = dtgHienThi.Rows[dong].Cells[0].Value.ToString();
            tbHoTen.Text = dtgHienThi.Rows[dong].Cells[1].Value.ToString();
            tbNgaySinh.Text = dtgHienThi.Rows[dong].Cells[2].Value.ToString();
            tbDT.Text = dtgHienThi.Rows[dong].Cells[3].Value.ToString();
            tbDiaChi.Text = dtgHienThi.Rows[dong].Cells[4].Value.ToString();
            tbGT.Text = dtgHienThi.Rows[dong].Cells[5].Value.ToString();
            tbTenDN.Text = dtgHienThi.Rows[dong].Cells[6].Value.ToString();
            tbPass.Text = dtgHienThi.Rows[dong].Cells[7].Value.ToString();
            tbQuyenDN.Text = dtgHienThi.Rows[dong].Cells[8].Value.ToString();
        }

        private void btGoBack_Click(object sender, EventArgs e)
        {
            FormNhanVien_Load(sender,e);
        }
    }
}
